package collection_.list;

import java.util.HashSet;
import java.util.Objects;

/**
 * @author 15594
 */
public class HashSet_ {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(123);
        hashSet.add(123);
        hashSet.add("aaa");
        hashSet.add(null);
        hashSet.add(null);
        hashSet.add(new String("str123"));
        hashSet.add(new String("str123"));
        hashSet.add(new User("lihua",1));
        hashSet.add(new User("lihua",1));

        for (Object o : hashSet) {
            System.out.println(o);
        }

    }
}
class User{
    private String name;
    private int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public User() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        User user = (User) o;
        return age == user.age &&
                Objects.equals(name, user.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
